package com.js.admin.rpc;

import com.js.admin.service.PermissionService;
import com.js.api.model.PermissionInfo;
import com.js.auth.client.annotation.CheckUserToken;
import com.js.auth.client.annotation.IgnoreUserToken;
import com.js.core.context.BaseContextHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ygl
 * @create 2018-10-31
 * @DESCRIPTION
 **/
@CheckUserToken
@RequestMapping("api")
@RestController
public class BaseUserApi {

    @Autowired
    private PermissionService permissionService;


    @RequestMapping(value = "/permissions", method = RequestMethod.GET)
    @IgnoreUserToken
    public @ResponseBody
    List<PermissionInfo> getAllPermission(){
        return permissionService.getAllPermission();
    }

    @RequestMapping(value = "/user/permissions", method = RequestMethod.GET)
    public @ResponseBody List<PermissionInfo> getPermissionByUsername(){
        return permissionService.getPermissionByUserId(BaseContextHandler.getUserId(),BaseContextHandler.getClientId());
    }

}
